
package traffic;



public class LightsControl 
{
    private Lights[][] lightMatrix = new Lights[10][10];
    
    public LightsControl()
    {
        createLightsMatrix();
    }
    
    private void createLightsMatrix()
    {
        int i, j;
        
        for(i = 0; i<10; i++)
        {
            for(j = 0; j<10; j++)
            {
                lightMatrix[i][j] = new Lights(i, j);
            }
        }
    }
    
    public Lights getLightFromMatrix(int i, int j)
    {
        return lightMatrix[i][j]; //neccessary for SwingGUI to have access to all of the functions
    }
    
    
    
    public void changeLights() //changes the greenstate variable in the light, which determines the direction that the green light is facing
    {
        int i, j;
        
        for(i = 0; i<10; i++)
        {
            for(j = 0; j<10; j++)
            {
                lightMatrix[i][j].changeLightState();
            }
        }
        
    }
    
    public void changeLightScheme1() //lights are either all red or all green on rows / columns
    {
        int i, j;
        
        for(i = 0; i < 10; i++)
        {
            for(j = 0; j < 10; j++)
            {
                lightMatrix[i][j].setLightState(0);
            }
        }
    }
    
    public void changeLightScheme2() //lights alternate red / green on any given row or column
    {
        int i, j;
        
        for(i = 0; i < 10; i++)
        {
            for(j = 0; j < 10; j++)
            {
                if(i%2 == 0)
                {
                    if(j%2 == 0)
                        lightMatrix[i][j].setLightState(0);
                    else
                        lightMatrix[i][j].setLightState(1);
                }
                else
                {
                    if(j%2 == 0)
                        lightMatrix[i][j].setLightState(1);
                    else
                        lightMatrix[i][j].setLightState(0);
                }
            }
        }
    }
}
